$(function() {
	
    var userBgImage = "imgs/bg" + Math.round(Math.random() * 3) + ".jpg";
    $("#bg").attr("src", userBgImage);
    $("#bluri").attr("src", userBgImage.replace("b", "blur"));
    // $(".login-choose").velocity("transition.slideUpBigIn");
    $("#bg").load(function() {
        $(".login-bg").velocity("fadeIn", 100, function() {
            $(".login-choose").velocity("transition.slideUpBigIn");
        })
    })
    $(document).keydown(function(e) {
        if (e.which == 13) {
            login();
        }
    })
    $(".swenpbtn").click(function() {
        var sq = [
            { e: $(".loginshcool-logo,.login-choose p,.fbtn-contaner"), p: "transition.fadeOut", o: { duration: 10 } },
            { e: $(".login-qrcode"), p: "transition.slideUpBigIn", o: { duration: 600, easing: "easeInOutExpo", display: "block" } },
            { e: $(".login-motto"), p: { "margin-top": "-20%", "width": "20%", }, o: { duration: 600, sequenceQueue: false, easing: "easeOutCirc" } }
        ]


        $("#bg").velocity("fadeOut", 300);
        $.Velocity.RunSequence(sq);
        if(!mobile_flag){
			$(".ps-tip").show();
		}else{
			$(".ps-tip").hide();
		}
    })
    $(".passwordbtn").click(function() {
        var sq = [
            { e: $(".loginshcool-logo,.login-choose p,.fbtn-contaner"), p: "transition.fadeOut", o: { duration: 10 } },
            { e: $(".login-username"), p: "transition.slideUpBigIn", o: { duration: 600, easing: "easeInOutExpo", display: "block" } },
            { e: $(".login-motto"), p: { "margin-top": "-20%", "width": "20%", }, o: { duration: 600, sequenceQueue: false, easing: "easeOutCirc" } }
        ]


        $("#bg").velocity("fadeOut", { duration: 300, display: "none" });
        $.Velocity.RunSequence(sq);
         if(!mobile_flag){
			$(".ps-tip").show();
		}else{
			$(".ps-tip").hide();
		}
    })
    $("#passwordlogin").click(function() {
        console.log("aaa")
        var ani = [{ e: $(".login-qrcode"), p: "transition.fadeOut", o: { duration: 10, display: "none" } },
            { e: $(".login-username"), p: "transition.slideUpBigIn", o: { duration: 600, easing: "easeInOutExpo", display: "block" } }

        ]
        $.Velocity.RunSequence(ani);
         if(!mobile_flag){
			$(".ps-tip").show();
		}else{
			$(".ps-tip").hide();
		}
    })
    $("#sweeploginaa").click(function() {
        console.log("aaa")
        var ani = [{ e: $(".login-username"), p: "transition.fadeOut", o: { duration: 10, display: "none" } },
            { e: $(".login-qrcode"), p: "transition.slideUpBigIn", o: { duration: 600, easing: "easeInOutExpo", display: "block" } }

        ]
        $.Velocity.RunSequence(ani);
         if(!mobile_flag){
			$(".ps-tip").show();
		}else{
			$(".ps-tip").hide();
		}
    })
})


function hasText(a) {
    if (typeof(a) == "undefined") {
        return false;
    }
    if (a == null) {
        return false;
    }
    if (a == "null") {
        return false;
    }
    if (typeof(a) == "string") {
        a = a.replace(/(^\s*)|(\s*$)/g, "");
    }
    if (a === "") {
        return false;
    }
    return true;
}

function login() {
    if (!hasText($(".userna").val())) {
        $(".userna").velocity("stop", true);
        $(".userna").velocity("callout.shake", { duration: 400 });
        return;
    }
    if (!hasText($(".passss").val())) {
        $(".passss").velocity("stop", true);
        $(".passss").velocity("callout.shake", { duration: 400 });
        return;
    }
}

function inital() {
    $("#bg").attr("src", userBgImage);
    $("#bluri").attr("src", userBgImage.replace("b", "blur"));
}